package com.janko.springbootbase.juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Description 类文件说明
 * @Author nieyankang
 * @Version 1.0
 * @date {date} {time}
 */
public class C2_CyclicTravelTask implements Runnable {
    String name;
    CyclicBarrier cyclicBarrier;
    int arriveTime;//赶到需要的时间

    public C2_CyclicTravelTask(CyclicBarrier cyclicBarrier, String name, int arriveTime) {
        this.cyclicBarrier = cyclicBarrier;
        this.name = name;
        this.arriveTime = arriveTime;
    }

    public C2_CyclicTravelTask(String name, int arriveTime) {
        this.name = name;
        this.arriveTime = arriveTime;
    }

    @Override
    public void run() {
        try {
            //模拟达到需要花的时间
            Thread.sleep(arriveTime * 1000);
            System.out.println(name + "到达集合点");
            cyclicBarrier.await();
            System.out.println(name + "开始旅行啦～～");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }finally {

        }
    }
}
